package org.colcon.web.server;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import org.colcon.web.model.framework.IItem;
import org.colcon.web.model.parsers.CLIParser;

public class ItemLoader 
{
	public static IItem[] load(String filepath) throws IOException
	{
		BufferedReader reader = new BufferedReader(new FileReader(filepath));
		
		List<IItem> list = new LinkedList<IItem>();
		
		String str = reader.readLine();
		
		while(str != null)
		{
			IItem item = CLIParser.parseItem(str);
			
			if(item != null)
				list.add(item);
			
			str = reader.readLine();
		}
		
		return list.toArray(new IItem[0]);
	}
}
